#!/usr/bin/perl

# parse goproblems.com HTML pages for rank suggestions and make those into PD
# ratings
#
# wget all relevant pages like
#   wget http://goproblems.com/prob.php3?id=5848
# then
#   grep -Po '\d+ (kyu|dan)(?=.*secs)' prob* | ./sgf_pd_from_goproblems.pl

use warnings;
use strict;

while (<>) {
    my ($file, $rank, $kyudan) = /(\d{4}):(\d+) (kyu|dan)/;
    my $rating;
    if ($kyudan eq 'kyu') {
        $rank = 20 if $rank > 20;
        $rating = 2100 - 100 * $rank;
    } elsif ($kyudan eq 'dan') {
        $rating = 2000 + 100 * $rank;
    } else {
        die "error: $_\n";
    }
    print "sgf_game_info.pl --PD $rating goproblems-$file.sgf\n";
}
